package com.pond.pond.controller;

import com.pond.common.core.domain.R;
import com.pond.common.core.web.controller.BaseController;
import com.pond.common.core.web.domain.AjaxResult;
import com.pond.common.core.web.page.TableDataInfo;
import com.pond.common.log.annotation.Log;
import com.pond.common.log.enums.BusinessType;
import com.pond.common.security.utils.SecurityUtils;
import com.pond.pond.domain.Appointment;
import com.pond.pond.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/appointment")
public class AppointmentController extends BaseController
{
    @Autowired
    private AppointmentService appointmentService;

    /**
     * 查询预约信息
     */
//    @RequiresPermissions("pond:appointment:list")
    @GetMapping("/list")
    public TableDataInfo list(Appointment appointment)
    {
        startPage();
        List<Appointment> list = appointmentService.selectAppointmentList(appointment);
        return getDataTable(list);
    }

    /**
     * 获取预约信息详细信息
     */
//    @RequiresPermissions("pond:appointment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appointmentService.selectAppointmentById(id));
    }

    /**
     * 新增预约信息
     */
//    @RequiresPermissions("pond:appointment:add")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Appointment appointment)
    {
        return toAjax(appointmentService.insertAppointment(appointment));
    }

    /**
     * 修改预约信息
     */
//    @RequiresPermissions("pond:appointment:edit")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Appointment appointment)
    {
        return toAjax(appointmentService.updateAppointment(appointment));
    }

    /**
     * 批量删除预约信息
     */
//    @RequiresPermissions("pond:appointment:remove")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appointmentService.deleteAppointmentByIds(ids));
    }

    /**
     * 删除预约信息
     */
//    @RequiresPermissions("pond:appointment:remove")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(appointmentService.deleteAppointmentById(id));
    }


    /**
     * 查询登陆用户的预约信息
     */
    @GetMapping("/user")
    public R<?> getInfo(Appointment appointment){
        Long userId = SecurityUtils.getUserId();
        return R.ok(appointmentService.selectAppointmentByUserId(userId));
    }
}
